// CodeContracts
// 
// Copyright (c) Microsoft Corporation
// 
// All rights reserved. 
// 
// MIT License
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics.Contracts;

namespace Tests.Sources
{
  class Base
  {
    public virtual void Test(string arg)
    {
      // make sure to call some other method to trigger recursion guards
      Contract.Requires(IsNotEqual(arg, null));
      if (String.IsNullOrEmpty(arg))
      {
        throw new ArgumentException("arg must be non-empty");
      }
      if (String.IsNullOrEmpty(arg))
      {
        throw new ArgumentException("arg must be non-empty still");
      }
      // make sure to call some other method to trigger recursion guards
      Contract.Requires(IsNotEqual(arg, null), "still");
      Contract.Requires(IsNotEqual(arg, null), "still2");
      Contract.Requires(IsEqual(arg, "foo")); // should take precedence over next
      if (!IsEqual(arg, "foo")) {
        throw new ArgumentException("arg must be equal to foo");
      }
      Contract.EndContractBlock();


      DoOtherStuff();
    }

    [Pure]
    public static bool IsNotEqual(object arg, object value) {
      return arg != value;
    }

    [Pure]
    public static bool IsEqual(object arg, object value) {
      return arg.Equals(value);
    }

    void DoOtherStuff() {}
  }

  partial class TestMain : Base
  {

    public override void Test(string arg) {
    }

    partial void Run()
    {
      if (behave)
      {
        this.Test("foo");
      }
      else
      {
        this.Test("bar");
      }
    }
    public ContractFailureKind NegativeExpectedKind = ContractFailureKind.Precondition;
    public string NegativeExpectedCondition = "IsEqual(arg, \"foo\")";
  }
}
